package com.zzl.car.config;

import com.zzl.car.handle.ZdpCrosFilter;
import com.zzl.car.handle.ZdpJwtHandler;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class zdpWebMvcConfig implements WebMvcConfigurer {
    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(new ZdpJwtHandler());
        //可以通过 InterceptorRegistration 来配置拦截的路径等待 和不拦截的路径
       /* interceptorRegistration.addPathPatterns();
        interceptorRegistration.excludePathPatterns();*/
    }

    /*
    * 注册过滤器
    * */
    @Bean
    public FilterRegistrationBean registFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ZdpCrosFilter());
        registration.addUrlPatterns("/*");
        registration.setName("CrosFilter");
        registration.setOrder(1);
        return registration;
    }
}
